from flask import Flask
from flasgger import Swagger
from config import Config

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)
    
    # 配置Swagger
    swagger_config = {
        "headers": [],
        "specs": [
            {
                "endpoint": 'apispec',
                "route": '/apispec.json',
                "rule_filter": lambda rule: True,  # all in
                "model_filter": lambda tag: True,  # all in
            }
        ],
        "static_url_path": "/flasgger_static",
        "swagger_ui": True,
        "specs_route": "/docs"
    }
    
    swagger_template = {
        "swagger": "2.0",
        "info": {
            "title": "地址向量化服务 API",
            "description": "基于Sentence-BERT的地址向量化和相似度查询服务",
            "version": "1.0.0",
            "contact": {
                "email": "your-email@example.com"
            }
        }
    }
    
    Swagger(app, config=swagger_config, template=swagger_template)
    
    # 注册蓝图
    from app.routes.api import bp as api_bp
    app.register_blueprint(api_bp, url_prefix='/api/v1')
    
    return app 